#!/bin/bash

# 因为涉及用 ruby 下载，所以要换源
gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/
bundle config mirror.https://rubygems.org https://gems.ruby-china.com

# 获取资源
mkdir -p ./resources
pushd ./resources || exit
gem fetch fiddle --version 1.1.4
gem fetch resolv --version 0.6.0
popd || exit

# 根据 workdir 设置 patch
sed -i "s|WORKDIR|$(pwd)|g" ./patches/jruby.patch

# 下载源码, 进行安装
wget -c https://github.com/jruby/jruby/archive/refs/tags/9.4.9.0.tar.gz
tar -zxf ./9.4.9.0.tar.gz
rm -rf ./9.4.9.0.tar.gz
pushd jruby-9.4.9.0/ || exit

# 应用 patch
patch -p1 <../patches/jruby.patch

# 安装
./mvnw install

popd || exit
